/**
 * Created by Tuffy on 16/1/18.
 */
'use strict';

angular.module('starter.controllers')
.controller('HotelsCtrl', ['$scope', '$state', function($scope, $state) {

    // 公海
    $scope.publicHotelView = function() {
        //$state.go('tab.hotels-list', {type: 'public'});
        $state.go('app.hotel-list-public');
    };

    // 私海
    $scope.privateHotelView = function() {
        //$state.go('tab.hotels-list', {type: 'private'});
        $state.go('app.hotel-list-private');
    };
}])
.controller('HotelMainCtrl', ['$rootScope', '$scope', '$state', '$cordovaToast', '$ionicLoading', 'HotelService', 'CrmHttp', function($rootScope, $scope, $state, $cordovaToast, $ionicLoading, HotelService, CrmHttp) {
    var init = function(){
            $scope.onTabChange(0);
            loadData();
        },
        loadData = function(){
            HotelService.getHotelBaseInfo($scope.hotelId)
                .success(function(res){
                    if(res.success && res.attribute.basicInfo){
                        var urls  = format( res.attribute.basicInfo);
                        if(urls.length>0){
                            $scope.HOTEL_PICS = urls;
                        }
                    }
                    if($scope.HOTEL_PICS.length<=0){
                    }
                    $scope.competitor = res.attribute.competitor;
                    if (!$rootScope.EDIT_DATE) {
                        $rootScope.EDIT_DATE = {};
                    }
                    $rootScope.EDIT_DATE.h_competitorList = res.attribute.competitor;
                }).error(function(error){

            }).finally(function(){

            });
        },format = function(data){
            if(!data.pics){
                return [];
            }
            var _hotelPics = JSON.parse(data.pics),
                def = [], //门头
                lobby = [], //大堂
                mainHousing = []; //主力房源
            for(var i in _hotelPics){
                var _thisPic = _hotelPics[i];
                if(_thisPic.name == 'def'){
                    def = _thisPic.pic;
                    if(def.length>0){
                        data['def'] = def;
                    }
                }else if(_thisPic.name == 'lobby'){
                    lobby = _thisPic.pic;
                    if(lobby.length>0){
                        data['lobby'] = lobby;
                    }
                }else if(_thisPic.name == 'mainHousing'){
                    mainHousing = _thisPic.pic;
                    if(mainHousing.length>0){
                        data['mainHousing'] = mainHousing;
                    }
                }
            }
            return def.concat(lobby).concat(mainHousing);
        };

    $scope.hotelId = $state.params.hotelId;

    $scope.HOTEL_PICS = [{
        url:'default'
    }];
    $scope.tabs = [{
        id:'1',
        name:'酒店信息',
        templateUrl:'templates/hotel-info-list.html'
    },{
        id:'2',
        name:'拜访信息',
        templateUrl:'templates/hotel-visit-list.html'
    },{
        id:'3',
        name:'评级信息',
        templateUrl:'templates/hotel-rank-list.html'
    }];
    $scope.onTabChange = function(index){
        $scope.active =  index;
        var _this = $scope.tabs[index];
        if(!_this.loaded){
            _this.loaded = true;
        }
    };

    // 提交审核
    $scope.checkSubmit = function() {

        // umeng count
        $rootScope.umengEventObj.onEventById('private_check');

        $ionicLoading.show({
            template: '执行中...'
        });
        CrmHttp.post('/crm/crmHotel/hotelCheck', {
            hotelId: $scope.hotelId
        }).then(function(resultData) {
            var res = resultData.data;
            if (res.success) {
                $cordovaToast.showShortBottom('提交成功');
            } else {
                $cordovaToast.showShortBottom(res.errorMsg);
            }
        }, function(error) {
            $cordovaToast.showShortBottom('提交失败，稍后再试');
        }).finally(function() {
            $ionicLoading.hide();
        });
    };

    init();
}])
.controller('HotelBaseInfoCtrl', ['$scope','$rootScope', '$state','HotelService','$cordovaToast',
    function($scope,$rootScope, $state,HotelService,$cordovaToast) {
    var type = 'HotelBaseInfo',
        hotelId = $state.params.hotelId,
        loadData = function(){
            HotelService.getHotelBaseInfo(hotelId)
                .success(function(res){
                    if(res.success && res.attribute.basicInfo){
                        $scope.hotel = format( res.attribute.basicInfo);
                    }else{
                        $cordovaToast.showShortBottom('酒店基础信息未设置');
                        //$scope.$ionicGoBack();
                    }
                }).error(function(error){
                    $cordovaToast.showShortBottom('获取酒店基础信息失败');
                    //$scope.$ionicGoBack();
            }).finally(function(){

            });
        },format = function(data){
            if(!data.pics){
                return data;
            }
            var _hotelPics = JSON.parse(data.pics),
                def = [], //门头
                lobby = [], //大堂
                mainHousing = []; //主力房源
            for(var i in _hotelPics){
                var _thisPic = _hotelPics[i];
                if(_thisPic.name == 'def'){
                    def = _thisPic.pic;
                    if(def.length>0){
                        data['def'] = def;
                    }
                }else if(_thisPic.name == 'lobby'){
                    lobby = _thisPic.pic;
                    if(lobby.length>0){
                        data['lobby'] = lobby;
                    }
                }else if(_thisPic.name == 'mainHousing'){
                    mainHousing = _thisPic.pic;
                    if(mainHousing.length>0){
                        data['mainHousing'] = mainHousing;
                    }
                }
            }
            return data;
        };
    /**
     * 编辑
     */
    $scope.doEdit = function(){
        if(!$rootScope.EDIT_DATE){
            $rootScope.EDIT_DATE = {};
        }
        $rootScope.EDIT_DATE[type] = _.clone($scope.hotel);
        $state.go('app.hotel-baseinfo-edit');
    };
    $rootScope.$on('EDIT_COMPLETE', function (event,result) {
       var hotel = result[type];
       if(hotel){
           $scope.hotel = hotel;
       }
    });
    if(hotelId){
        loadData();
    }
}])
.controller('HotelLocationCtrl', ['$scope','$rootScope', '$state','HotelService','$cordovaToast',
    function($scope,$rootScope, $state,HotelService,$cordovaToast) {

    var type = 'HotelLocationEdit',
        hotelId = $state.params.hotelId,
        loadData = function(){
            HotelService.getHotelPosition(hotelId)
                .success(function(res){
                    if(res.success && res.attribute.hotelPosition){
                        $scope.hotel = res.attribute.hotelPosition;
                    }else{
                        $cordovaToast.showShortBottom('酒店位置信息未设置');
                        //$scope.$ionicGoBack();
                    }
                }).error(function(error){
                //$scope.$ionicGoBack();
                $cordovaToast.showShortBottom('获取酒店位置信息失败');
            }).finally(function(){

            });
        };

    /**
     * 编辑
     */
    $scope.doEdit = function(){
        if(!$rootScope.EDIT_DATE){
            $rootScope.EDIT_DATE = {};
        }
        $rootScope.EDIT_DATE[type] = _.clone($scope.hotel);
        $state.go('app.hotel-location-edit');
    };
    $rootScope.$on('EDIT_COMPLETE', function (event,result) {
        var hotel = result[type];
        if(hotel){
            loadData();
        }
    });
    if(hotelId){
        loadData();
    }
}])
.controller('HotelFacilityCtrl', ['$scope','$rootScope', '$state','HotelService','$cordovaToast','$ionicLoading','$ionicScrollDelegate',
    function($scope,$rootScope, $state,HotelService,$cordovaToast,$ionicLoading,$ionicScrollDelegate) {
    var hotelId = $state.params.hotelId,
        format = function(result){
            var all = result.all,
                hotel = result.hotel ? result.hotel : {};
            for(var key in all){
                var items = all[key],
                    group = {
                        id:'group'+$scope.groups.length,
                        name:key,
                        items:items
                    };
                angular.forEach(items,function(item){
                    if(hotel[item.id]){
                        item.checked = true;
                    }
                });
                $scope.groups.push(group);
            }
            $scope.selectGroup = hotel;
        },
        getSaveData = function(){
            var saveData = [],
                keys = Object.keys($scope.selectGroup);
            for(var i in  keys){
                saveData.push(keys[i]);
            }
            return saveData.join(',');
        },
        loadData = function(){
            //$ionicLoading.show({
            //    template: '<ion-spinner ionc="ios"></ion-spinner>'
            //});
            HotelService.getFacility(hotelId)
                .success(function(res){
                    if(res.success){
                        format(res.attribute);
                    }else{
                        //$cordovaToast.showShortBottom('酒店设施信息未设置');
                        //$scope.$ionicGoBack();
                    }
                }).error(function(error){
                //$scope.$ionicGoBack();
                $cordovaToast.showShortBottom('获取酒店设施信息失败');
            }).finally(function(){
                $ionicLoading.hide();
            });
        };
    /**
     * 保存
     */
    $scope.doSave = function(){
        $ionicLoading.show({
            template: '保存中...'
        });
        var params = {
            'hotelId':$rootScope.EDIT_HOTEL.id,
            'ids':getSaveData()
        };
        HotelService.setFacility(params)
            .success(function(res){
                if(res.success){
                    $cordovaToast.showShortBottom('保存成功');
                }else{
                    $cordovaToast.showShortBottom('保存失败');
                }
            })
            .error(function(){

            })
            .finally(function(){
                $ionicLoading.hide();
            });
    };

    $scope.groups = [];
    $scope.onChange = function(item,checked){
        if(checked){
            $scope.selectGroup[item.id] = item.name;
        }else{
            delete $scope.selectGroup[item.id];
        }
    };
    $scope.myScroll = {
        selected:'group0',
        getNextId : function(id){
            for(var i=0;i< $scope.groups.length;i++){
                var tagId = $scope.groups[i].id;
                if(tagId==id){
                    return i==$scope.groups.length-1 ? id : $scope.groups[i+1].id;
                }
            }
            return id;
        },
        getPreId : function(id) {
            for (var i = 0; i < $scope.groups.length; i++) {
                var tagId = $scope.groups[i].id;
                if (tagId == id) {
                    return i == 0 ? id : $scope.groups[i - 1].id;
                }
            }
            return id;
        },
        onScroll : function() {
            var that = this,
                contentHeight = $ionicScrollDelegate.$getByHandle('mainScroll').getScrollView().__contentHeight-$ionicScrollDelegate.$getByHandle('mainScroll').getScrollView().__clientHeight,
                top = $ionicScrollDelegate.$getByHandle('mainScroll').getScrollPosition().top,
                id = that.selected,
                curTop = document.getElementById(id).offsetTop,
                nextId = that.getNextId(id),
                nextTop = document.getElementById(nextId).offsetTop,
                preId = that.getPreId(id),
                preTop = document.getElementById(preId).offsetTop;
            if(contentHeight<20){ //bug fixed
                $ionicScrollDelegate.$getByHandle('mainScroll').resize();
                return;
            }
            if(top>=contentHeight){
                that.selected = $scope.groups[$scope.groups.length-1].id;
            }else if(top>=preTop && top<curTop){
                that.selected = preId;
            }else if(top>=nextTop){
                that.selected = nextId;
            }else if(top>=curTop && top<nextTop){ //当前模块内
                return;
            }
            $scope.$apply();
        },
        scrollTo: function(tagId){
            var scroll = document.getElementById(tagId).offsetTop - $ionicScrollDelegate.$getByHandle('mainScroll').getScrollPosition().top;
            $ionicScrollDelegate.$getByHandle('mainScroll').resize();
            $ionicScrollDelegate.$getByHandle('mainScroll').scrollBy(0,scroll,true);
        }
    };

    if(hotelId){
        loadData();
    }
}])
.controller('HotelContactCtrl', ['$scope','$rootScope', '$state','HotelService','$cordovaToast',
    function($scope,$rootScope, $state,HotelService,$cordovaToast) {
    var hotelId = $state.params.hotelId,
        type = 'HotelContactEdit';
    /**
     * contact
     */
    $scope.contacts ={
        page: {
            pageNum:1,
            pageSize:10,
            total:200
        },
        loaded:false,
        data:[],
        loadData:function(){
            var _this = this,
                params = {
                    hotelId:hotelId,
                    pageNum:_this.page.pageNum,
                    pageSize:_this.page.pageSize
                };
            _this.loaded = false;
            HotelService.getContacts(params)
                .success(function(res){
                    if(res.success){
                        _this.data = _this.data.concat(res.attribute.rows);
                        _this.page.total = res.attribute.total;
                    }else{
                        _this.page.total = 0;
                        console.log('加载失败');
                    }
                }).error(function(error){
                _this.page.total = 0;
                console.log(error);
            }).finally(function(){
                _this.loaded = true;
                $scope.$broadcast('scroll.refreshComplete');
            });
        },
        refresh:function(){
            this.page.pageNum = 1;
            this.data = [];
            this.loadData();
        }
    };

    $scope.contactDict = {
        '1':'老板',
        '2':'前台',
        '3':'经理',
        '4':'其他'
    };
    $scope.modifyContact = function(user){
        if ($rootScope.isPrivateFlag) {
            var contact = angular.copy(user);
            delete contact.$$hashKey;
            delete contact.hotelId;
            delete contact.createTime;
            delete contact.updateTime;
            contact.roleId = contact.roleId + "";
            $rootScope.EDIT_DATE[type] = contact;
            $state.go("app.hotel-contact-edit");
        }

    };

    $rootScope.$on('EDIT_COMPLETE', function (event,result) {
        var contact = result[type];
        if(contact){
            $scope.contacts.refresh();
        }
    });
    if(hotelId){
        $scope.contacts.loadData();
    }
}])
.controller('HotelRoomTypeListCtrl', ['$scope', '$state','HotelService','$cordovaToast',
    function($scope, $state,HotelService,$cordovaToast) {
    var hotelId = $state.params.hotelId,
        format = function(dataList){
            for(var index in dataList){
                var data = dataList[index],
                    _hotelPics = data.pics?JSON.parse(data.pics):[],
                    def = [], //门头
                    lobby = [], //大堂
                    mainHousing = []; //主力房源
                for(var i in _hotelPics){
                    var _thisPic = _hotelPics[i];
                    if(_thisPic.name == 'def'){
                        def = _thisPic.pic;
                        if(def.length>0){
                            data['def'] = def[0].url;
                        }
                    }else if(_thisPic.name == 'lobby'){
                        lobby = _thisPic.pic;
                        if(lobby.length>0){
                            data['lobby'] = lobby[0].url;
                        }
                    }else if(_thisPic.name == 'mainHousing'){
                        mainHousing = _thisPic.pic;
                        if(mainHousing.length>0){
                            data['mainHousing'] = mainHousing[0].url;
                        }
                    }
                }
            }
            return dataList;
        };

    /**
     * roomTypes
     */
    $scope.roomTypes ={
            search: {
                value:'',
                filter:{},
                doAct:function(){
                    if(this.timer){
                        $timeout.cancel(this.timer);
                    }
                    this.timer = $timeout(function(){
                        $scope.roomTypes.page.pageNum = 1;
                        $scope.roomTypes.data = [];
                        $scope.roomTypes.loadData();
                    },500);
                }
            },
            page: {
                pageNum:0,
                pageSize:10,
                total:0
            },
            loaded:false,
            data:[],
            loadData:function(){
                var _this = this,
                    params = {
                        hotelId:hotelId,
                        pageNum:_this.page.pageNum,
                        pageSize:_this.page.pageSize
                    };
                _this.loaded = false;
                for(var key in _this.search.filter){
                    params[key] = _this.search.filter[key];
                }
                HotelService.getRoomTypeList(params)
                    .success(function(res){
                        if(res.success && res.attribute.roomListInfo){
                            _this.data = format(res.attribute.roomListInfo);
                            _this.page.total = _this.data.length;
                        }else{
                            _this.page.total = 0;
                            console.log('加载失败');
                        }
                    }).error(function(error){
                    _this.page.total = 0;
                    console.log(error);
                }).finally(function(){
                    _this.loaded = true;
                    $scope.$broadcast('scroll.refreshComplete');
                    $scope.$broadcast('scroll.infiniteScrollComplete');
                });
            },
            //moreDataCanBeLoaded:function(){
            //    return this.page.total > this.page.pageNum*this.page.pageSize;
            //},
            //loadMore:function(){
            //    this.page.pageNum++;
            //    this.loadData();
            //},
            refresh:function(){
                this.page.pageNum = 1;
                this.data = [];
                this.loadData();
            }
        } ;
    if(hotelId){
        $scope.roomTypes.loadData();
    }
}])
.controller('HotelRoomTypeDetailCtrl', ['$scope','$rootScope', '$state','HotelService','$cordovaToast',
    function($scope,$rootScope, $state,HotelService,$cordovaToast) {
    var type = 'HotelRoomInfoEdit',
        roomTypeId = $state.params.roomTypeId,
        format = function(data){
            if(!data.pics){
                return {};
            }
            var _hotelPics = JSON.parse(data.pics),
                def = [], //门头
                bed = [], //床
                toilet = []; //卫生间
            for(var i in _hotelPics){
                var _thisPic = _hotelPics[i];
                if(_thisPic.name == 'def'){
                    def = _thisPic.pic;
                    if(def.length>0){
                        data['def'] = def;
                    }
                }else if(_thisPic.name == 'bed'){
                    bed = _thisPic.pic;
                    if(bed.length>0){
                        data['bed'] = bed;
                    }
                }else if(_thisPic.name == 'toilet'){
                    toilet = _thisPic.pic;
                    if(toilet.length>0){
                        data['toilet'] = toilet;
                    }
                }
            }
            return data;
        },
        loadData = function(){
            HotelService.getRoomTypeInfo(roomTypeId)
                .success(function(res){
                    if(res.success && res.attribute.hotelRoomInfo){
                        $scope.hotelRoomInfo = format(res.attribute.hotelRoomInfo);
                        $scope.hotelRoomInfo['roomTypeId'] = roomTypeId;
                    }else{
                        $cordovaToast.showShortBottom('房型信息未设置');
                        //$scope.$ionicGoBack();
                    }
                }).error(function(error){
                //$scope.$ionicGoBack();
                $cordovaToast.showShortBottom('获取房型信息失败');
            }).finally(function(){

            });
        }
    /**
     * 编辑
     */
    $scope.doEdit = function(){

        // umeng count
        $rootScope.umengEventObj.onEventById('private_edit');

        if(!$rootScope.EDIT_DATE){
            $rootScope.EDIT_DATE = {};
        }
        $rootScope.EDIT_DATE[type] = _.clone($scope.hotelRoomInfo);
        $state.go('app.hotel-room-info-edit');
    };
    $rootScope.$on('EDIT_COMPLETE', function (event,result) {
        var hotelRoomInfo = result[type];
        if(hotelRoomInfo){
            //$scope.hotelRoomInfo = hotelRoomInfo;
            loadData();
        }
    });
    if(roomTypeId){
        loadData();
    }
}])
.controller('HotelActivationCtrl', ['$scope','$rootScope', '$state','HotelService','$cordovaToast','$ionicPopup',
function($scope,$rootScope, $state,HotelService,$cordovaToast,$ionicPopup) {
    $scope.ac = {
       /* hotelName:"泰州兴化市会友旅馆",
        hotelAddr:"泰州市",
        hotelCode:"123456",
        hotelStatusName:"未激活",
        hotelStatus:"1"*/
    }
    $scope.ac.noData = true;//默认没有数据
    var hotelId = $state.params.hotelId;
    $scope.selectPmsHotels = function(){
        HotelService.selectPmsHotels(hotelId)
            .success(function(res){
                if(res.success  && res.attribute){
                    $scope.ac = res.attribute;
                    $scope.ac.noData = false;
                }else{
                    $scope.ac.errorMsg = res.errorMsg;
                    $cordovaToast.showShortBottom('查询失败');
                }
            }).error(function(error){
            $cordovaToast.showShortBottom('查询失败');
        }).finally(function(){

        });
    };

    $scope.showDeleteConfirm = function(){
       // $ionicLoading.hide();
        var confirmPopup = $ionicPopup.confirm({
            title: '酒店删码',
            template: "确认删除？",
            cancelText: '取消',
            okText: '确定'
        });
        confirmPopup.then(function (res) {
            if (res) {
                $scope.doDelete();
            }
        });
    };

    $scope.doDelete = function(){
        /*if($scope.ac.hotelStatus == '1'){
            $cordovaToast.showShortBottom('酒店未激活不能删除');
            return ;
        }*/

        HotelService.deletePmsHotels(hotelId)
        .success(function(res){
            if(res.success){
                $cordovaToast.showShortBottom('删除成功');
            }else{
                console.log(res.errorMsg);
                $cordovaToast.showShortBottom(res.errorMsg);
            }
        }).error(function(error){
            console.log(res.errorMsg);
            $cordovaToast.showShortBottom(res.errorMsg);
        }).finally(function(){

        });
    };
    $scope.selectPmsHotels();
}])
.service('HotelService',['CrmHttp','$rootScope',function(CrmHttp,$rootScope){
    var url = '/crm/crm-hotel-public/';
    return {
        /**
         * 全部公海酒店
         * @param params
         * @returns {*}
         */
        findListPublic: function (params) {
            var act = 'getHotels';
            params['isPrivate'] = '2';
            params['hotel_user_id'] = $rootScope.localStorageObj.userId;
            return CrmHttp.post(url + act, params);
        },
        /**
         * 全部私海酒店
         * @param params
         * @returns {*}
         */
        findListPrivate: function (params) {
            var act = 'getHotels';
            params['isPrivate'] = '1';
            params['hotel_user_id'] = $rootScope.localStorageObj.userId;
            return CrmHttp.post(url + act, params);
        },
        /**
         * 全部酒店
         * @param params
         * @returns {*}
         */
        findList: function (params) {
            var act = 'find-list';
            return CrmHttp.post(url + act, params);
        },
        /**
         * 获取基础信息
         * @param params
         * @returns {*}
         */
        getHotelBaseInfo: function (hotelId) {
            var act = 'getHotelBaseInfo',
                params = {};
            params['hotelId'] = hotelId;
            return CrmHttp.post(url + act, params);
        },
        /**
         * 获取位置
         * @param params
         * @returns {*}
         */
        getHotelPosition: function (hotelId) {
            var act = 'getHotelPosition',
                params = {};
            params['hotelId'] = hotelId;
            return CrmHttp.post(url + act, params);
        },
        /**
         * 获取酒店设施
         * @param params
         * @returns {*}
         */
        getFacility: function (hotelId) {
            var act = 'getFacility',
                params = {};
            params['hotelId'] = hotelId;
            return CrmHttp.post(url + act, params);
        },
        /**
         * 获取某个酒店通讯录
         * @param params
         * @returns {*}
         */
        getContacts: function (params) {
            var act = 'find-list-byId';
            return CrmHttp.post('/crm/crm-hotel-role/' + act, params);
        },
        /**
         * 获取房型列表
         * @param params
         * @returns {*}
         */
        getRoomTypeList: function (params) {
            var act = 'getRoomTypeList';
            return CrmHttp.post(url + act, params);
        },
        /**
         * 获取某个房型信息
         * @param params
         * @returns {*}
         */
        getRoomTypeInfo: function (roomTypeId) {
            var act = 'getRoomTypeInfo',
                params = {};
            params['id'] = roomTypeId;
            return CrmHttp.post(url + act, params);
        },
        /**
         * 认领酒店
         * @param hotelId
         * @returns {*}
         */
        assign:function(hotelId){
            var act = 'assign',
                params = {};
            params['hotelId'] = hotelId;
            params['hotelUserId'] = $rootScope.localStorageObj.userId;
            params['operationUserId'] = $rootScope.localStorageObj.userId;
            return CrmHttp.post(url + act, params);
        },
        /**
         * 保存酒店设施
         * @param hotelId
         * @returns {*}
         */
        setFacility:function(params){
            var act = 'setFacility';
            return CrmHttp.post(url + act, params);
        },
        /**
         * 保存酒店基本信息
         * @param hotelId
         * @returns {*}
         */
        setHotelBasicInfo:function(params){
            var act = 'setHotelBasicInfo';
            return CrmHttp.post(url + act, params);
        },
        /**
         * 保存房型信息
         * @param hotelId
         * @returns {*}
         */
        setRoomTypeInfo:function(params){
            var act = 'setRoomTypeInfo';
            return CrmHttp.post(url + act, params);
        },
        /**
         * 收藏
         * @param hotelId
         * @returns {*}
         */
        favoriteAdd:function(hotelId){
            var act = 'insert',
                params = {};
            params['hotelId'] = hotelId;
            params['userId'] = $rootScope.localStorageObj.userId;
            return CrmHttp.post('/crm/my-favorite/' + act, params);
        },
        /**
         * 取消收藏
         * @param hotelId
         * @returns {*}
         */
        favoriteRemove:function(hotelId){
            var act = 'cancel',
                params = {};
            params['hotelId'] = hotelId;
            params['userId'] = $rootScope.localStorageObj.userId;
            return CrmHttp.post('/crm/my-favorite/' + act, params);
        },
        /**
         * 查询激活码
         * @param hotelId
         * @returns {*}
         */
        selectPmsHotels:function(hotelId){
            var act = 'searchPmsHotelById',
            params = {};
            params['userId'] = hotelId;
            return CrmHttp.post('/pmsController/' + act, params);
        },
        /**
         * 删除激活码
         * @param hotelId
         * @returns {*}
         */
        deletePmsHotels:function(hotelId){
            var act = 'deleteRegisterInfo',
            params = {};
            params['code'] = hotelId;
            params['userId'] = $rootScope.localStorageObj.userId;
            return CrmHttp.post('/pmsController/' + act, params);
        }
    };
}]);
